package com.ky.client.service;

import java.util.Scanner;

import com.ky.client.util.RequestUtil;
import com.ky.common.dto.Dto;
import com.ky.common.entity.KyUser;
import com.ky.common.util.KeyConstants;

public class LoginService implements Service {

	@Override
	public Service service() {

		Scanner scanner = new Scanner(System.in);
		Service nextService = null;
		System.out.print("请输入用户名：");
		String userName=scanner.next();
		System.out.print("请输入密码：");
		String userPwd=scanner.next();
		//创建dto对象
		Dto<KyUser> requestDto = new Dto<>();
		requestDto.setKey(KeyConstants.LOGIN);
		requestDto.setData(new KyUser(userName, userPwd));
		RequestUtil<KyUser> requestUtil = new RequestUtil<>();
		Dto<Object> responseDto = requestUtil.request(requestDto);
		//判断响应码是否为200
		if(responseDto.getCode()==200) {
			System.out.println("登录成功，即将进入文件列表展示页面。。。。。。");
			nextService=new FileListService();
		}else {
			System.out.println("登录失败，原因："+responseDto.getErrorMsg());
		}
		System.out.print("继续操作请输入y，返回开始页请输入n。请输入：");
		String choice=scanner.next();
		if("n".equals(choice)) {
			nextService=new StartService();
		}
		
		return nextService;
	}

}
